/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mx.itschapala.dsw2.invernadero.vista;

import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ActionEvent;
import mx.itschapala.dsw2.invernadero.BL.DayBLLocal;
import mx.itschapala.dsw2.invernadero.BL.PaymentBLLocal;
import mx.itschapala.dsw2.invernadero.BL.StaffBLLocal;
import mx.itschapala.dsw2.invernadero.modelo.Day;
import mx.itschapala.dsw2.invernadero.modelo.Payment;
import mx.itschapala.dsw2.invernadero.modelo.Staff;

/**
 *
 * @staff Raven
 */
@ManagedBean
@SessionScoped
public class StaffBean {
    @EJB
    private DayBLLocal dayBL;
    @EJB
    private PaymentBLLocal paymentBL;
    @EJB
    private StaffBLLocal staffBL;
    
    
    
        //------------------Variables--------------------
private List<Staff> lista;
private List<Payment>listaPay;
private List<Day>listaDay;
private Staff staff;
private Payment pay;
private Day dia;
private String accion;
private int n;

    /**
     * Creates a new instance of StaffBean
     */
    public StaffBean() {
    }
    
    //------------------------Metodo Get y Set-------------

    public List<Payment> getListaPay() {
        listaPay=paymentBL.getAll();
        return listaPay;
    }

    public List<Day> getListaDay() {
        listaDay=dayBL.getList();
        return listaDay;
    }

    public Payment getPay() {
        return pay;
    }

    public void setPay(Payment pay) {
        this.pay = pay;
    }

    public Day getDia() {
        return dia;
    }

    public void setDia(Day dia) {
        this.dia = dia;
    }
    
    

    
    
    
    
    
    ///////////////////////////////////////////////////////////
    public List<Staff> getLista() {
        lista=staffBL.getList();
        return lista;
    }

    public Staff getStaff() {
        return staff;
    }

    public void setStaff(Staff staff) {
        this.staff = staff;
    }
    
    //-----------------Acciones------------------------------
    public String procesarAccion(){
        if(accion.equalsIgnoreCase("Nuevo")){
        staffBL.register(staff);
        }
        else
        if(accion.equalsIgnoreCase("Editar")){
            staffBL.modify(staff);
        }
        else if(accion.equalsIgnoreCase("Eliminar")){
            staffBL.delete(staff);
         
         
        }
        accion="";
    return "Trabajador";
    }
    
    
   public String limpiarAccion(){
   staff=new Staff();
   return "TrabajadorCrearEditar";
    }
//-----------------Listener------------------------------

public void prepararNuevo(ActionEvent evt){
staff=new Staff();
accion="Nuevo";
}
public void prepararEditar(ActionEvent evt)   
{
System.out.println(evt.getComponent().getClientId());
 n=Integer.parseInt(evt.getComponent().getClientId().split(":")[2]);
    System.out.println("el numero es:"+n);
    staff=lista.get(n);
    accion="Editar";
}     


public void prepararEliminar(ActionEvent evt)   
{
    int x;
System.out.println(evt.getComponent().getClientId());
 n=Integer.parseInt(evt.getComponent().getClientId().split(":")[2]);
    System.out.println("el numero es:"+n);
    staff=lista.get(n);
   
    
    accion="Eliminar";
}    


public void buscaR()
{
staff=staffBL.findName("YO");
    System.out.println(staff.getFirstName());
}
    
    
}
